package com.biao.cloud.controller;

import com.biao.cloud.entities.Payment;
import com.biao.cloud.entities.Result;
import com.biao.cloud.service.PaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
public class PaymentController {

    @Autowired
    private PaymentService paymentService;

    @Value("${server.port}")
    private String serverPort;

    @PostMapping("/payment/create")
    public Result<Payment> create(@RequestBody Payment payment) {
        int i = paymentService.create(payment);
        log.info("插入结果" + i);
        if (i > 0) {
            return new Result(200, "在" + serverPort + "插入成功", i);
        } else {
            return new Result(444, "在" + serverPort + "插入失败");
        }
    }

    @GetMapping("/payment/get/{id}")
    public Result<Payment> getPaymentById(@PathVariable("id") Long id) {
        Payment payment = paymentService.getPaymentById(id);
        log.info("查询" + payment);
        return new Result(200, "在" + serverPort + "查询成功了, id:" + id, payment);
    }

    @GetMapping(value = "/payment/lb")
    public String getPaymentLB() {
        return serverPort;
    }
}
